﻿package net.wangit.view.chart.util;

import net.wangit.MapList;
import net.wangit.Row;
import net.wangit.util.Checker;

import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.data.xy.DefaultXYDataset;
import org.jfree.data.xy.XYDataset;


public class DatasetUtil {

	public DatasetUtil() {
	}

	public static CategoryDataset toCategoryDataset(MapList list) {
		if (Checker.isEmpty(list))
			return null;
		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		for (int i = 0; i < list.size(); i++) {
			Row row = list.getRow(i);
			dataset.addValue(new Double(row.get("y")), row.get("r"), row
					.get("c"));
		}

		return dataset;
	}

	public static PieDataset toPieDataset(MapList list) {
		if (Checker.isEmpty(list))
			return null;
		DefaultPieDataset dataset = new DefaultPieDataset();
		for (int i = 0; i < list.size(); i++) {
			Row row = list.getRow(i);
			dataset.setValue(row.get("c"), new Double(row.get("y")));
		}

		return dataset;
	}

	public static XYDataset toXYDataset(MapList list) {
		if (Checker.isEmpty(list))
			return null;
		DefaultXYDataset dataset = new DefaultXYDataset();
		for (int i = 0; i < list.size(); i++)
			;
		return dataset;
	}
}
